package com.jmb.api.controller.module;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.jmb.api.common.result.Result;
import com.jmb.api.service.ModuleService;
import com.jmb.api.vo.module.ModuleInfoVo;
import com.jmb.api.vo.module.ModuleUpdateVo;
import com.jmb.api.vo.module.ModuleVo;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.validation.Valid;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Slf4j
@Tag(name = "模块管理")
@RestController
@RequestMapping("module")
public class ModuleController {
    @Autowired
    private ModuleService moduleService;

    @Operation(summary = "模块管理新增")
    @PostMapping("save")
    public Result addModule(@RequestBody @Valid ModuleVo moduleVo){
        moduleService.saveModule(moduleVo);
        return Result.ok();
    }

    @Operation(summary = "模块管理修改")
    @PostMapping("update")
    public Result updateModule(@RequestBody @Valid ModuleUpdateVo moduleUpdateVO){
        moduleService.updateModule(moduleUpdateVO);
        return Result.ok();
    }
    @Operation(summary = "模块管理列表")
    @GetMapping("list")
    public Result<IPage<ModuleInfoVo>> getModuleList(@RequestParam(defaultValue = "1") Integer pageNum, @RequestParam(defaultValue = "10") Integer pageSize, String projectName, String moduleName){
        IPage<ModuleInfoVo> page = new Page<>(pageNum, pageSize);
        IPage<ModuleInfoVo> list = moduleService.getModuleList(page,projectName,moduleName);
        return Result.ok(list);
    }
    @Operation(summary = "模块管理删除")
    @GetMapping("remove")
    public Result removeModule(Integer moduleId){
        moduleService.removeById(moduleId);
        return Result.ok();
    }
    @Operation(summary = "模块管理查询")
    @GetMapping("moduleId")
    public Result getModuleById(@RequestParam Integer moduleId){
        ModuleInfoVo moduleInfoVo = moduleService.getModuleById(moduleId);
        return Result.ok(moduleInfoVo);
    }
}
